#include <QtGui/QDialog>
#include <QtGui/QPushButton>
#include <QtGui/QLineEdit>
#include <QObject>
#include <QtGui/QHBoxLayout>
#include <QtGui>

#include "keyWordSearch.h"
#include "resultItem.h"
#include "database_connection.h"

KeyWordSearch::KeyWordSearch(QWidget *parent)
    : QDialog(parent)
{
    resize(800, 480);
    searchBtn = new QPushButton(tr("Search"));
    searchLineEdit = new QLineEdit;
    groupBox = new QGroupBox(this);
    pageUp = new QPushButton("上一页");
    pageDown = new QPushButton("下一页");

    connect(searchBtn, SIGNAL(triggered()), this, SLOT(searchDevice()));

    QHBoxLayout *topLayout = new QHBoxLayout;
    topLayout->addWidget(searchLineEdit);
    topLayout->addWidget(searchBtn);
    topLayout->addStretch();
    topLayout->addWidget(pageUp);
    topLayout->addWidget(pageDown);

    bottomLayout = new QGridLayout;

    QVBoxLayout *mainLayout = new QVBoxLayout;
    mainLayout->addLayout(topLayout);
    mainLayout->addWidget(groupBox);

    setLayout(mainLayout);
    setWindowTitle("关键字查询");
}

void KeyWordSearch::searchDevice()
{
    delete bottomLayout;
    QSqlDatabase::database().transaction();
    QSqlQuery query;

    QString searchContent = searchLineEdit->text();

    query.exec("");
    while(query.next())
    {

    }
    QSqlDatabase::database().commit();
}
